import { Button, Form, Input } from "antd";
import { publish } from "../../api/flask";

type FieldType = {
    title: string;
    content: string;
}

const Index = () => {
    const [form] = Form.useForm<FieldType>();

    const onFinish = (values: FieldType) => {
        publish(values).then(() => {
            alert('post success')
        })
    };
    return (
        <div>
            <Form
                form={form}
                name="basic"
                labelCol={{ span: 8 }}
                wrapperCol={{ span: 16 }}
                style={{ maxWidth: 600 }}
                initialValues={{ remember: true }}
                onFinish={onFinish}
                autoComplete="off"
            >
                <Form.Item<FieldType>
                    label="标题"
                    name="title"
                    required
                >
                    <Input />
                </Form.Item>


                <Form.Item<FieldType>
                    label="内容"
                    name="content"
                    required
                >
                    <Input.TextArea />
                </Form.Item>


                <Form.Item label={null}>
                    <Button type="primary" htmlType="submit">
                        Submit
                    </Button>
                </Form.Item>
            </Form>
        </div>
    )
}

export default Index